package com.yiwan.app.preventionsis.util;

import android.content.Context;
import android.util.DisplayMetrics;

public class ScreenResolution {

    /**
     * ����ֻ�ķֱ��ʴ� dp �ĵ�λ ת��Ϊ px(����)
     */
    public static int dip2px(float dpValue) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * ����ֻ�ķֱ��ʴ� px(����) �ĵ�λ ת��Ϊ dp
     */
    public static int px2dip(float pxValue) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    public static DisplayMetrics getDM() {
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        return dm;
    }

    public static int getSceenWidthInDP() {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        return (int) (dm.widthPixels / scale + 0.5f);
    }

    public static int getSceenHeightInDP() {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        return (int) (dm.heightPixels / scale + 0.5f);
    }

    public static int getSceenHeightInPix() {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        return (int) dm.heightPixels;
    }

    public static int getSceenWidthInPix() {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        return (int) dm.widthPixels;
    }

    private static Context getContext() {
        return PreventionSis.getInstance();
    }
}